<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
  <script src="./vue-router.js"></script>
  <style>
    .box {
      width: 200px;
      height: 300px;
      position: absolute;
    }

    .position {
      background: greenyellow;
    }

    .search {
      background: rgb(241, 221, 133);
    }

    .profile {
      background: rgb(133, 152, 233);
    }

    .slide-left-enter,
    .slide-right-leave-to
    {
      opacity: 0;
      transform: translateX(-100%);
    }

    .slide-left-enter-active,
    .slide-left-leave-active,
    .slide-right-enter-active,
    .slide-right-leave-active
    {
      transition: all .3s;
    }

    .slide-left-leave-to,
    .slide-right-enter
    {
      opacity: 0;
      transform: translateX(100%);
    }
  </style>
</head>

<body>

  <div id="app">
    <router-link tag="button" to="/position">职位</router-link>
    <router-link tag="button" to="/search">搜索</router-link>
    <router-link tag="button" to="/profile">我的</router-link>
    <transition :name="transitionname" mode="in-out">
      <router-view></router-view>
    </transition>
  </div>


  <script>

    var position = { template: `<div class="box position">position</div>` }
    var search = { template: `<div  class="box search">search</div>` }
    var profile = { template: `<div  class="box profile">profile</div>` }

    var routes = [
      {
        path: "/",
        redirect: '/position',
      },
      {
        path: '/position',
        component: position,
        meta: { order: 1 }
      },
      {
        path: '/search',
        component: search,
        meta: { order: 2 }

      },
      {
        path: '/profile',
        component: profile,
        meta: { order: 3 }

      }
    ]

    var router = new VueRouter({
      routes
    })

    var vm = new Vue({
      data: {
        transitionname: 'slide-left'
      },
      watch: {
        '$route'(to, from) {
          if (to.meta.order > from.meta.order) {
            this.transitionname = 'slide-right'
          } else {
            this.transitionname = 'slide-left'
          }
        }
      },
      router
    }).$mount('#app')

  </script>

</body>

</html>